package com.liutaw.nanjingair.views.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.GridView;

import com.liutaw.nanjingair.R;
import com.liutaw.nanjingair.models.WeatherProduct;
import com.liutaw.nanjingair.views.adapter.WeatherProductAdapter;
import com.liutaw.navigationbarlib.NaviBarBuilder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ProductsFragment extends Fragment {

    @Bind(R.id.navi_container)
    FrameLayout navi_container;
    NaviBarBuilder navigationBarView;
    @Bind(R.id.gridview_baseproduct)
    GridView gridview_baseproduct;
    WeatherProductAdapter baseProductAdapter;
    @Bind(R.id.gridview_professional)
    GridView gridview_professional;
    WeatherProductAdapter proProductAdapter;
    @Bind(R.id.gridview_other)
    GridView gridview_other;
    WeatherProductAdapter otherProductAdapter;

    private List<WeatherProduct> weatherProductList;
    private List<WeatherProduct> proProductList;
    private List<WeatherProduct> otherProductList;

    public ProductsFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_fragment_products, container, false);
        ButterKnife.bind(this, view);
        navigationBarView = new NaviBarBuilder(getActivity());
        navigationBarView.buildCenterView().buildTitleText("气象产品");
        navi_container.addView(navigationBarView.build());
        initData();


        gridview_baseproduct.setAdapter(baseProductAdapter);
        gridview_professional.setAdapter(proProductAdapter);
        gridview_other.setAdapter(otherProductAdapter);

        return view;
    }

    private void initData() {
        initBaseData();
        initProData();
        initOtherData();
    }

    private void initBaseData() {
        weatherProductList = new ArrayList<>();
        weatherProductList.add(WeatherProduct.getInstance("天气预报",R.drawable.icon_wxyt));
        weatherProductList.add(WeatherProduct.getInstance("卫星云图",R.drawable.icon_wxyt));
        weatherProductList.add(WeatherProduct.getInstance("雷达图像",R.drawable.icon_ldtx));
        weatherProductList.add(WeatherProduct.getInstance("台风路径",R.drawable.icon_tflj));
        weatherProductList.add(WeatherProduct.getInstance("趋势预测",R.drawable.icon_qsyc));
        weatherProductList.add(WeatherProduct.getInstance("实况信息",R.drawable.icon_skxx));
        weatherProductList.add(WeatherProduct.getInstance("统计信息",R.drawable.icon_tjxx));
        weatherProductList.add(WeatherProduct.getInstance("重要天气",R.drawable.icon_zytq));
        weatherProductList.add(WeatherProduct.getInstance("气候评价",R.drawable.icon_qhpj));
        weatherProductList.add(WeatherProduct.getInstance("气象预警",R.drawable.icon_qxyj));
        baseProductAdapter = new WeatherProductAdapter(getContext(),weatherProductList);
    }

    private void initProData() {
        proProductList = new ArrayList<>();
        proProductList.add(WeatherProduct.getInstance("农业气象",R.drawable.icon_nyqx));
        proProductList.add(WeatherProduct.getInstance("生活气象",R.drawable.icon_shqx));
        proProductList.add(WeatherProduct.getInstance("环境天气",R.drawable.icon_hjtq));
        proProductList.add(WeatherProduct.getInstance("森林火灾",R.drawable.icon_slhz));
        proProductList.add(WeatherProduct.getInstance("交通气象",R.drawable.icon_jtqx));
        proProductList.add(WeatherProduct.getInstance("日出日落",R.drawable.icon_rcrl));
        proProductList.add(WeatherProduct.getInstance("农历节气",R.drawable.icon_nljq));
        proProductList.add(WeatherProduct.getInstance("实况上传",R.drawable.icon_sksc));
        proProductAdapter = new WeatherProductAdapter(getContext(),proProductList);
    }

    private void initOtherData() {
        otherProductList = new ArrayList<>();
        otherProductList.add(WeatherProduct.getInstance("微博气象",R.drawable.icon_wbqx));
        otherProductList.add(WeatherProduct.getInstance("气象新闻",R.drawable.icon_qxxw));
        otherProductAdapter = new WeatherProductAdapter(getContext(),otherProductList);
    }


}
